package com.Impl;

import com.entity.Root;
import com.service.LoginService;
import com.utils.JDBCUtil;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.junit.Test;

import java.lang.annotation.Target;
import java.sql.Connection;
import java.sql.SQLException;

public class RootLogin implements LoginService {
    private  QueryRunner queryRunner = new QueryRunner();
    private Connection connection;
    @Override
    public Root queryForRoot(String username) {
        connection = JDBCUtil.getConnection();
        String sql="select username,password from root where username=?";
        try {
            Root queryRoot = queryRunner.query(connection, sql, new BeanHandler<Root>(Root.class),username);
            return queryRoot;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
    @Test
    public void testConnection(){
        Connection connection = JDBCUtil.getConnection();
        System.out.println(connection);
    }
    @Test
    public void testQueryForRoot(){
        connection = JDBCUtil.getConnection();
        String sql="select username,password from root where username=?";
        try {
            Root queryRoot = queryRunner.query(connection, sql, new BeanHandler<Root>(Root.class),"h790864074");
            System.out.println(queryRoot);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
